package com.tj.collection.controller.chatter.request;

import com.fqgj.common.utils.StringUtils;
import com.tj.collection.controller.BaseCompent;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Data
@ApiModel(value = "chatterListRequest", description = "chatter列表请求参数")
public class ChatterListRequest implements Serializable {
    @ApiModelProperty("分页参数：当前页码")
    private Integer current = 1;
    @ApiModelProperty("分页参数：每页最大展示条数")
    private Integer pageSize = 30;
    @ApiModelProperty("chatter account")
    private String account;
    @ApiModelProperty("chatter名称")
    private String nickName;
    @ApiModelProperty("在线状态：1-在线 2-离线")
    private Integer onlineStatus;
    @ApiModelProperty("model code")
    private String modelUserCode;
    @ApiModelProperty("账号状态：1-disabled 2-enable")
    private Integer status;
    @ApiModelProperty("在线评级：1-S 2-A 3-B")
    private Integer level;
    @ApiModelProperty("工作类型：1-Full 2-PartTime")
    private Integer jobType;
    @ApiModelProperty("国家或地区：All-All PAK-Pakistan MX-Mexico PH-Philippines")
    private String area;

    public Map<String, Object> setUpQueryParams(@RequestBody ChatterListRequest request, BaseCompent.AccountRole accountRole) {

        Map<String, Object> params = new HashMap<>();
        if (StringUtils.isNotEmpty(request.getNickName())) {
            params.put("nickName", request.getNickName());
        }
        if (StringUtils.isNotEmpty(request.getAccount())) {
            params.put("account", request.getAccount());
        }
        if (request.getOnlineStatus() != null) {
            params.put("onlineStatus", request.getOnlineStatus());
        }
        if (StringUtils.isNotEmpty(request.getModelUserCode())) {
            params.put("modelUserCode", request.getModelUserCode());
        }
        if (request.getStatus() != null && request.getStatus() != 99) {
            params.put("status", request.getStatus());
        }
        if (request.getLevel() != null && request.getLevel() != 99) {
            params.put("level", request.getLevel());
        }
        if (request.getJobType() != null && request.getJobType() != 99) {
            params.put("jobType", request.getJobType());
        }

        if (StringUtils.isNotEmpty(request.getArea())) {
            params.put("area", request.getArea());
        }
        if (!accountRole.getHasViewAllDataPermission()) {
            params.put("chatterCodes", accountRole.getChatterCodes());
        }
        return params;
    }

}
